# Maintainer: Jan Jasper de Kroon <jajadekroon@gmail.com>
pkgname=linux-pine64-pinephonepro
pkgver=6.11.11
_pkgver=6.11
_tagdate=20241206-0145
pkgrel=1
pkgdesc="Mainline kernel for the pinephone pro"
arch="aarch64"
_flavor="${pkgname#linux-}"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	pmb:kconfigcheck-pinephonepro
	"
makedepends="
	bash
	bison
	findutils
	flex
	gmp-dev
	gzip
	linux-headers
	mpc1-dev
	mpfr-dev
	openssl-dev
	perl
	postmarketos-installkernel
	rsync
	xz
	"

case "$CARCH" in
	aarch64*) _carch="arm64" ;;
	arm*) _carch="arm" ;;
esac

# Source
_config="config-$_flavor.$CARCH"
source="
	https://gitlab.com/pine64-org/linux/-/archive/ppp-$_pkgver-$_tagdate/linux-ppp-$_pkgver-$_tagdate.tar.gz
	config-$_flavor.aarch64
	"
builddir="$srcdir/linux-ppp-$_pkgver-$_tagdate"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$CARCH" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))"

}

package() {
	mkdir -p "$pkgdir"/boot
	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs-$_flavor
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}


sha512sums="
065ceac6e0e6f3b7b939977084a1ac5aeabbff0273c61e50d0c2374825e0b1b41511592e54cb74a3d3d59a17fd5cc90018f6612062eb0f6b78dde29dd1aeade9  linux-ppp-6.11-20241206-0145.tar.gz
9e68b276f86b59cd9960b8d287530c8e7780fafa0ee5389225339671861666dff1a66fff225e0d4d4f1de949cd2449bc3dd5499ef8ad6519d5b596776f148207  config-pine64-pinephonepro.aarch64
"
